package main

import "fmt"

func produce(nums []int) chan int {
	out := make(chan int)
	go func() {
		for _, num := range nums {
			out <- num
		}
		close(out)
	}()
	return out
}

func consume(waitProcess chan int) chan int {
	out := make(chan int)
	go func() {
		for p := range waitProcess {
			out <- p * p
		}
		close(out)
	}()
	return out
}

func main() {
	var nums = produce([]int{2, 3, 4, 5, 6})
	var results = consume(nums)
	results = consume(consume(results))
	for result := range results {
		fmt.Println(result)
	}
}
